/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package doan2database;

/**
 *
 * @author DongVan
 */

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;


public class ChiTietHoaDon {
    private int m_IDChiTietHoaDon;
	private int m_IDVe;
	private int m_IDHoaDon;
	public int getM_IDChiTietHoaDon() {
		return m_IDChiTietHoaDon;
	}
	public void setM_IDChiTietHoaDon(int m_IDChiTietHoaDon) {
		this.m_IDChiTietHoaDon = m_IDChiTietHoaDon;
	}
	public int getM_IDVe() {
		return m_IDVe;
	}
	public void setM_IDVe(int m_IDVe) {
		this.m_IDVe = m_IDVe;
	}
	public int getM_IDHoaDon() {
		return m_IDHoaDon;
	}
	public void setM_IDHoaDon(int m_IDHoaDon) {
		this.m_IDHoaDon = m_IDHoaDon;
	}
	public ChiTietHoaDon(int m_IDChiTietHoaDon, int m_IDVe, int m_IDHoaDon) {
		this.m_IDChiTietHoaDon = m_IDChiTietHoaDon;
		this.m_IDVe = m_IDVe;
		this.m_IDHoaDon = m_IDHoaDon;
	}
	
	public ChiTietHoaDon(){
		
	}
	
	
	AESEncrypt aes = new AESEncrypt();
	Datapro dataprovider = new Datapro();
	
	public ArrayList<ChiTietHoaDon> selected() {
		ArrayList<ChiTietHoaDon> listChiTietHoaDon = new ArrayList<ChiTietHoaDon>();
		String sqlQuery = "select * from CHI_TIET_HOA_DON";
		ResultSet rs = dataprovider.Selected(sqlQuery);
		try {
			while (rs.next()) {
				ChiTietHoaDon itemChiTietHoaDon = new ChiTietHoaDon();
				itemChiTietHoaDon.m_IDChiTietHoaDon = rs.getInt(1);
				itemChiTietHoaDon.m_IDVe = rs.getInt(2);
				itemChiTietHoaDon.m_IDHoaDon = rs.getInt(3);
				listChiTietHoaDon.add(itemChiTietHoaDon);
			}
			dataprovider.disconnect();
	        rs.close();
	        return listChiTietHoaDon;
	        
	    } catch ( SQLException ex) {
	        Logger.getLogger(Datapro.class.getName()).log(Level.SEVERE, null, ex);
	    }
		return null;
	}
	

	public boolean insert() {
		int idVe = this.m_IDVe;
		int idHoaDon = this.m_IDHoaDon;
		String query =  "insert into CHI_TIET_HOA_DON values("+idVe+","+ idHoaDon + ")";
		boolean result =  dataprovider.Insert(query);
		dataprovider.disconnect();
		return result;
	}
	
	public boolean update(){
		int idVe = this.m_IDVe;
		int idHoaDon = this.m_IDHoaDon;
		String query = "update CHI_TIET_HOA_DON set IDVe = "+ idVe +", IDHoaDon = "+idHoaDon+"  where IDLoaiND = " + this.m_IDChiTietHoaDon + "\"";
		boolean result = dataprovider.Update(query);
		dataprovider.disconnect();
		return result;
	}
	
	public boolean delete(){
		String query = "delete from CHI_TIET_HOA_DON where = " + this.m_IDChiTietHoaDon + "\"";
		boolean result = dataprovider.Delete(query);
		dataprovider.disconnect();
		return result;
	}
}
